'use client'; import Link from 'next/link'; import { useState } from 'react'; import { Heart, MoreHorizontal, CornerDownRight } from 'lucide-react'; import { fetchApi } from '@/lib/utils/client'; import useAuth from '@/hooks/useAuth'; import { formatDate } from '@/lib/utils/client'; import { FeedReply } from '@/types/feed/post'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; type Props = { reply: FeedReply; onReply: (target: FeedReply) => void; onDelete: (id: number) => void; }; export default function FeedReplyItem({ reply, onReply, onDelete }: Props) { const { loginCheck } = useAuth(); const [likes, setLikes] = useState(reply.likes); const [liked, setLiked] = useState(reply.hasLike); const [busy, setBusy] = useState(false); const handleLike = async () => { if (!loginCheck() || busy || reply.isDeleted) { return; } setBusy(true); try { const res = await fetchApi<{ hasLike: boolean; likes: number }>(`/api/feed/comment/${reply.id}/like`, { method: 'POST', silent: true }); if (res.success && res.data) { setLiked(res.data.hasLike); setLikes(res.data.likes); } } catch (err) { console.error(err); } finally { setBusy(false); } }; const handleDelete = async () => { if (!confirm('이 댓글을 삭제할까요?')) { return; } try { const res = await fetchApi(`/api/feed/comment/${reply.id}`, { method: 'DELETE', silent: true }); if (res.success) { onDelete(reply.id); } } catch (err) { console.error(err); } }; const authorDisplay = reply.authorName || reply.authorSID || '알 수 없음'; const avatarInitial = (authorDisplay.charAt(0) || '?').toUpperCase(); const parentName = reply.parentAuthorName || reply.parentAuthorSID; return (
{reply.authorSID ? ( {reply.authorThumb ? ( {authorDisplay} ) : ( {avatarInitial} )} ) : ( {avatarInitial} )}
{reply.authorSID ? ( {authorDisplay} ) : ( {authorDisplay} )} · {formatDate(reply.createdAt)} {reply.isOwner && !reply.isDeleted && ( 삭제 )}
{parentName && reply.parentID && (
{parentName}님에게
)} {reply.isDeleted ? (

삭제된 답글입니다.

) : (

{reply.content}

)} {!reply.isDeleted && ( )}
); }